home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / TurboTCP 2.0.1 / TurboTCP source / CTCPResolverCall.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-21  |  5.4 KB  |  171 lines  |  [TEXT/MPCC]

  1. /*
  2. ** CTCPResolverCall.h
  3. **
  4. **    TurboTCP support library
  5. **    TCP resolver class
  6. **
  7. **    Copyright © 1993-94, FrostByte Design / Eric Scouten
  8. **
  9. */
  10.  
  11.  
  12. #pragma once
  13.  
  14. #include "TCL.h"
  15.  
  16. #include <Types.h>                            // get <ConditionalMacros.h> if available
  17. #if (defined(GENERATINGPOWERPC) || defined(GENERATING68K))
  18. #include <MacTCP.h>                            // Universal Headers 2.0
  19. #else
  20. #include <MacTCPCommonTypes.h>                // Univ Headers 1.0 or old headers
  21. #include <AddressXlation.h>
  22. #define GENERATINGCFM USESROUTINEDESCRIPTORS
  23. #define Result2UPP ResultProc2UPP
  24. #define NewResult2Proc NewResultProc2Proc
  25. #endif
  26.  
  27. #include "CTCPDriver.h"
  28. #include "CTCPEndpoint.h"
  29.  
  30. #ifndef TCL_NO_TEMPLATES
  31.     class CTCPResolverCallList;
  32. #else
  33.     class CPtrArray_CTCPResolverCall;
  34.     #define CTCPResolverCallList CPtrArray_CTCPResolverCall
  35. #endif
  36.  
  37.  
  38. // notification types for PostponeNotify()
  39.  
  40. enum NotifType {
  41.     notifNone,
  42.     notifStrToAddr,
  43.     notifAddrToName,
  44.     notifHInfo,
  45.     notifMXInfo
  46. };
  47.  
  48. typedef enum NotifType NotifType;
  49.  
  50.  
  51.  
  52. /*______________________________________________________________________
  53. **
  54. ** CTCPResolverCall
  55. **
  56. **    This class implements the core DNR calls. It is like the CTCPAsyncCall in that the call
  57. **    object is created to allow the call to persist beyond the scope of originating method.
  58. **    However, access to this object is not restricted; your application classes can and often
  59. **    will interact with the CTCPResolverCall object.
  60. **
  61. **    Each resolver object may support only one asynchronous resolver call at a time.
  62. **    You may create several resolver objects to simultaneously process several calls,
  63. **    so long as you respect MacTCP’s limit of 8 resolver calls open at once. The CTCPDriver
  64. **    acts as a referee to prohibit more than 8 simultaneous calls.
  65. **
  66. **    One set of methods (Do...) is called to initiate resolver calls. These are the methods you
  67. **    will typically call from your application classes. These methods initiate asynchronous
  68. **    calls to the DNR code resource. When the calls are completed, the notification is passed
  69. **    to another set of methods (Handle...). The Handle… methods return notification to your
  70. **    class through the Handle… methods in CTCPProtcolInterp. The exception to this is the
  71. **    DoAddrToStr method which returns the result immediately.
  72. **
  73. **    The userDataPtr fields of each of the calls are used by the resolver object to get
  74. **    notification of completion, and are not available to the caller.
  75. **
  76. **    The CTCPDriver object takes care of opening and closing the DNR code resource; it uses
  77. **    the OpenResolver and CloseResolver methods. You should not call these methods from your
  78. **    application classes.
  79. **
  80. **    The EnumCache call is not implemented in TurboTCP.
  81. **
  82. **    TurboTCP 1.0 NOTE: This class is no longer a descendant of CCollaborator. It now
  83. **    communicates only with the CTCPEndpoint mix-in class.
  84. **
  85. */
  86.  
  87. class CTCPResolverCall TCL_AUTO_DESTRUCT_OBJECT {
  88.  
  89.     friend class CTCPDriver;
  90.     friend class CTCPResolverList;
  91.     friend class UTurboTCP;
  92.  
  93.     #ifdef TCL_NO_TEMPLATES
  94.         friend class CPtrArray_CTCPResolverCall;
  95.     #endif
  96.  
  97.     TCL_DECLARE_CLASS;
  98.  
  99. private:
  100.     CTCPEndpoint*            itsEndpoint;            // endpoint object for this resolver
  101.     Boolean                inUse;                // resolver in use; can’t accept calls
  102.     Boolean                disposeOnCompletion;    // dispose of resolver call once completed
  103.     hostInfo                theHostInfo;            // parms for StrToAddr
  104.     returnRec                theHMXInfo;            // parms for HInfo or MXInfo
  105.     char                    hostName[255];        // name of user host
  106.     NotifType                pendingNotify;            // resolver is in ProcessNotify queue
  107.     static Handle            macDNRcode;            // the DNR code resource’s handle
  108.     static UniversalProcPtr    macDNRentry;            // the DNR code entry point
  109.     TurboTCPQElem            qEntry;                // completion queue entry
  110.  
  111. #if GENERATINGCFM
  112.     static ResultUPP        StrToAddrUPP;            // UPPs for all DNR callbacks
  113.     static ResultUPP        AddrToNameUPP;
  114.     static Result2UPP        HInfoUPP;
  115.     static Result2UPP        MXInfoUPP;
  116. #endif
  117.  
  118.  
  119.     // constructor/destructor
  120.  
  121. public:
  122.                     CTCPResolverCall(CTCPEndpoint& theEndpoint);
  123. private:
  124.     virtual            ~CTCPResolverCall();        // use Dispose() instead
  125. public:
  126.     void                Dispose();
  127.  
  128.  
  129.     // initiate resolver calls
  130.     
  131.     void                DoStrToAddr(char* theHostName);
  132.     static void        DoAddrToStr(ip_addr theIPaddr, char* theString);
  133.     void                DoAddrToName(ip_addr theIPaddr);
  134.     void                DoHInfo(char* theHostName);
  135.     void                DoMXInfo(char* theHostName);
  136.  
  137.  
  138.     // respond to completion of resolver calls
  139.  
  140. private:
  141.     void                ProcessNotify();
  142.     inline void            HandleStrToAddr()
  143.                         { if (itsEndpoint) itsEndpoint->HandleStrToAddr(&theHostInfo); }
  144.     inline void            HandleAddrToName()
  145.                         { if (itsEndpoint) itsEndpoint->HandleAddrToName(&theHostInfo); }
  146.     inline void            HandleHInfo()
  147.                         { if (itsEndpoint) itsEndpoint->HandleHInfo(&theHMXInfo); }
  148.     inline void            HandleMXInfo()
  149.                         { if (itsEndpoint) itsEndpoint->HandleMXInfo(&theHMXInfo); }
  150.  
  151.  
  152.     // open/close TCP resolver
  153.  
  154.     static void        OpenResolver();
  155.     static void        CloseResolver();
  156.     static short        OpenTheDNR();
  157.     static short        SearchFolderForDNRP(long targetType, long targetCreator, short vRefNum, long dirID);
  158.     static void        GetSystemFolder(short* vRefNumP, long* dirIDP);
  159.     static void        GetCPanelFolder(short* vRefNumP, long* dirIDP);
  160.  
  161.  
  162.     // interrupt-level methods: delay processing for non-interrupt status
  163.  
  164.     void                PostponeNotify(NotifType theNotifType);
  165.     static pascal void    PostponeStrToAddr(hostInfo* hostInfoPtr, char* userDataPtr);
  166.     static pascal void    PostponeAddrToName(hostInfo* hostInfoPtr, char* userDataPtr);
  167.     static pascal void    PostponeHInfo(returnRec* returnRecPtr, char* userDataPtr);
  168.     static pascal void    PostponeMXInfo(returnRec* returnRecPtr, char* userDataPtr);
  169.  
  170. };
  171.